<?php

require_once __DIR__ . '/../autoload.php';

use  src\DataBase;

$username = $_COOKIE['school']['username'];
$db = new DataBase\DataBaseOperate('139.196.124.180', 'school', 'user1', 'Mcx857264', 'utf8');
$selectResult = $db->select('courseSelectionRecord', '*', array('studentInfo' => $username), 'insertTime', 6);
if($selectResult)
{
    foreach ($selectResult as $key => $singleItem)
    {
        $selectResult[$key][5] = date('Y-m-d H:i:s', $singleItem[5]);
        if($singleItem[6] == 1)
        {
            $selectResult[$key][6] = '取消';
        }
        else
        {
            $selectResult[$key][6] = '带签到';
        }
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>正在加载</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="description" content="Write an awesome description for your new site here.">
    <link rel="stylesheet" href="css/weui.css" type="text/css">
    <link rel="stylesheet" href="https://cdn.bootcss.com/weui/0.4.3/style/weui.min.css" type="text/css">
    <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/0.8.0/css/jquery-weui.min.css" type="text/css">
    <link rel="stylesheet" href="css/demos.css">
</head>

<body ontouchstart>

<div class='demos-content-padded'>
    <?php if ($selectResult != null) {
        $output = json_encode($selectResult);
        $file = file_put_contents("./json/" . $username . ".json", $output);
        ?>
        <div class="weui-loadmore">
            <i class="weui-loading"></i>
            <span class="weui-loadmore__tips">正在加载</span>
        </div>
        <div class="weui-loadmore weui-loadmore_line">
             <span class="weui-loadmore__tips">
		         <H4 class="center"><input type="text" style='font-size:18px; border:0px; width:20px;' readonly="true" value="5" id="time">秒</H4>
			</span>
        </div>
    <?php } else { ?>
        <div class="weui-loadmore weui-loadmore_line">
            <span class="weui-loadmore__tips">暂无数据</span>
        </div>
        <div class="weui-loadmore weui-loadmore_line weui-loadmore_dot">
            <span class="weui-loadmore__tips"></span>
        </div>
    <?php } ?>

</div>

<script src="js/jquery-2.1.4.js"></script>
<script src="js/fastclick.js"></script>
<script>
    $(function () {
        FastClick.attach(document.body);
    });
</script>
<script src="https://cdn.bootcss.com/jquery-weui/0.8.0/js/jquery-weui.min.js"></script>

<script type="text/javascript">
    var t = 5;
    var time = document.getElementById("time");

    function fun() {
        t--;
        time.value = t;
        if (t <= 0) {
            location.href = "./template/historyCourse.php";
            clearInterval(inter);
        }
    }

    var inter = setInterval("fun()", 1000);
</script>
</body>
</html>
